package com.iyoudoock.citymine.activity.user;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.iyoudoock.citymine.BaseActivity;
import com.iyoudoock.citymine.R;
import com.iyoudoock.citymine.constants.Key;
import com.iyoudoock.citymine.constants.Value;
import com.kvin.toolkit.utils.JumpUtils;
import com.kvin.toolkit.utils.TipsUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ChangeIdentityActivity extends BaseActivity {

    @BindView(R.id.nick_name_et)
    EditText nickNameEt;
    @BindView(R.id.male_rad)
    RadioButton maleRad;
    @BindView(R.id.female_rad)
    RadioButton femaleRad;
    @BindView(R.id.sex_rg)
    RadioGroup sexRg;
    @BindView(R.id.age_et)
    EditText ageEt;
    @BindView(R.id.phone_et)
    EditText phoneEt;
    @BindView(R.id.service_district_tv)
    TextView serviceDistrictTv;
    @BindView(R.id.change_identity_tv)
    TextView changeIdentityTv;


    private TipsUtils mTips;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_identity);
        ButterKnife.bind(this);
    }

    @Override
    public void initNav() {
        setTitle("身份变更");
    }

    @Override
    public void init() {
        initTips();
        userName = mPersistentUtils.readString(Key.User.NICK_NAME);
        String sex = mPersistentUtils.readString(Key.User.SEX);
        phoneNo = mPersistentUtils.readString(Key.User.TELEPHONE);
        String age = mPersistentUtils.readString(Key.User.AGE);
        String district = mPersistentUtils.readString(Key.User.DISTRICT);
        mRoleType = mPersistentUtils.readString(Key.User.ROLE_TYPE);

        nickNameEt.setText(userName);
        nickNameEt.setClickable(false);

        if (sex.equals(Value.SEX_BOY)) {
            ((RadioButton) sexRg.getChildAt(0)).setChecked(true);
        } else {
            ((RadioButton) sexRg.getChildAt(1)).setChecked(true);
        }

        this.ageEt.setText(age);
        this.ageEt.setClickable(false);

        this.phoneEt.setText(phoneNo);
        this.phoneEt.setClickable(false);

        this.serviceDistrictTv.setText(district);

        if (mRoleType.equals(Value.Role.COMMUNITY)) {
            this.changeIdentityTv.setText("当前身份为社区回收商");
        } else if (mRoleType.equals(Value.Role.FLUENT)) {
            this.changeIdentityTv.setText("当前身份为流动回收商");
        }

        this.changeIdentityTv.setOnClickListener(this);

    }

    /**
     * init tips
     */
    private void initTips() {
        mTips = TipsUtils.getInstance(this);
        mTips.setTitle("温馨提示");
        mTips.setDesc("您确定要变更身份吗？");
        mTips.setOnCancelClickListener(mOnCancelClick);
        mTips.setOnConfirmClickListener(mOnConfirmClick);
    }


    @Override
    public void onClick(View v) {
        if (mRoleType.equals(Value.Role.FLUENT)) {
            JumpUtils.simpleJump(getActivity(), UpdateServiceDistrictActivity.class);
            return;
        }
        mTips.show();
    }

    /**
     * tips cancel click
     */
    private View.OnClickListener mOnCancelClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mTips.dismiss();
        }
    };
    /**
     * tips confirm click
     */
    private View.OnClickListener mOnConfirmClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            changeIdentity("", Value.Role.FLUENT);
            mTips.dismiss();
        }
    };
}
